﻿using DatabaseAccess;
using Liguo.AppCode;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Liguo.Store
{
    public partial class GetBackPassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            String UserName = Request.QueryString["uid"];
            String key = Request.QueryString["key"];
            SqlIt sql = new SqlIt();
            if ((UserName != null && UserName.Length > 0 && Utilities.IsCJKChar(UserName)) && (key != null && key.Length == 64))
            {
                DataSet ds = sql.SpecialItem("UserInfo", "UserName='" + UserName + "'");
                if (ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["XTime"] != DBNull.Value)
                    {
                        DateTime XTime = Convert.ToDateTime(ds.Tables[0].Rows[0]["XTime"]);
                        if (XTime.AddDays(1).CompareTo(DateTime.Now) > 0)
                        {
                            String XCode = ds.Tables[0].Rows[0]["XCode"].ToString();
                            if (XCode.Equals(key))
                            {
                                Session.Add("UserName", UserName);
                                Session.Timeout = 5;
                                Response.Write("<script>alert(\"验证通过，请尽快修改密码！\");</script>");
                            }
                            else
                            {
                                //error_code=1
                                //校验码错误，请重新发送验证邮件！
                                Response.Redirect("GetBackPasswordError.aspx?error=1");
                            }
                        }
                        else
                        {
                            //error_code=2
                            //校验码过期，请重新发送验证邮件！
                            Response.Redirect("GetBackPasswordError.aspx?error=2");
                        }
                    }
                    else
                    {
                        //error_code=3
                        //无有效校验码，请重新发送验证邮件！
                        Response.Redirect("GetBackPasswordError.aspx?error=3");
                    }
                }
                else
                {
                    //error_code=4
                    //用户不存在
                    Response.Redirect("GetBackPasswordError.aspx?error=4");
                }
            }
            else
            {
                //error_code=5
                //uid错误
                //请不要随便修改URL！
                Response.Redirect("GetBackPasswordError.aspx?error=5");
            }
        }
    }
}